/*     */ package com.asiainfo.dacp.catalog.controller;
/*     */ 
/*     */ import com.asiainfo.dacp.jdbc.JdbcTemplate;
/*     */ import java.sql.PreparedStatement;
/*     */ import java.sql.SQLException;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Calendar;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.jdbc.core.PreparedStatementSetter;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/catalog"})
/*     */ public class PortalKpiValueController
/*     */ {
/*  28 */   private static Logger LOG = LoggerFactory.getLogger(PortalKpiValueController.class);
/*     */   
/*     */   @RequestMapping(value={"/portalkpivalue"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   @ResponseBody
/*     */   public Object portalkpivalue(HttpServletRequest request, HttpServletResponse response) {
/*  33 */     Map<String, String> result = new HashMap();
/*     */     try {
/*  35 */       JdbcTemplate template = new JdbcTemplate();
/*  36 */       List<Map<String, Object>> kpis = template.queryForList("select KPI_CODE,KPI_NAME,KPI_SQL from dacp_kpi_def");
/*  37 */       for (Map<String, Object> kpi : kpis) {
/*  38 */         final String kpicode = (String)kpi.get("KPI_CODE");
/*  39 */         final String kpiname = (String)kpi.get("KPI_NAME");
/*  40 */         String kpisql = (String)kpi.get("KPI_SQL");
/*  41 */         final double value = ((Integer)template.queryForObject(kpisql, Integer.TYPE)).intValue();
/*  42 */         Calendar c = Calendar.getInstance();
/*  43 */         c.setTime(new Date());
/*  44 */         c.add(5, -1);
/*  45 */         final String optime = new SimpleDateFormat("yyyy/MM/dd").format(c.getTime());
/*  46 */         c.add(5, -1);
/*  47 */         String yesteday = new SimpleDateFormat("yyyy/MM/dd").format(c.getTime());
/*  48 */         int predvaluecount = ((Integer)template.queryForObject("select COUNT(1) from dacp_kpi_value where OPTIME='" + yesteday + "' and KPI_CODE='" + kpicode + "'", Integer.TYPE)).intValue();
/*     */         Object dratex;
/*     */         Object predvaluex;
/*  51 */         Object dratex; if (predvaluecount == 1) {
/*  52 */           Object predvaluex = template.queryForObject("select KPI_VALUE from dacp_kpi_value where OPTIME='" + yesteday + "' and KPI_CODE='" + kpicode + "'", Integer.TYPE);
/*  53 */           Object dratex; if (((Integer)predvaluex).intValue() == 0) { Object dratex;
/*  54 */             if ((int)value == 0) {
/*  55 */               dratex = Integer.valueOf(0);
/*     */             } else {
/*  57 */               dratex = Integer.valueOf(1);
/*     */             }
/*     */           } else {
/*  60 */             dratex = Double.valueOf((value - ((Integer)predvaluex).intValue()) / ((Integer)predvaluex).intValue());
/*     */           }
/*     */         } else {
/*  63 */           predvaluex = null;
/*  64 */           dratex = null;
/*     */         }
/*  66 */         Object predvalue = predvaluex;
/*  67 */         final Object drate = dratex;
/*  68 */         c.add(5, 1);
/*  69 */         c.add(2, -1);
/*  70 */         String lastmonth = new SimpleDateFormat("yyyy/MM/dd").format(c.getTime());
/*  71 */         int premvaluecount = ((Integer)template.queryForObject("select count(1) from dacp_kpi_value where OPTIME='" + lastmonth + "' and KPI_CODE='" + kpicode + "'", Integer.TYPE)).intValue();
/*     */         Object mratex;
/*     */         Object premvaluex;
/*  74 */         Object mratex; if (premvaluecount == 1) {
/*  75 */           Object premvaluex = template.queryForObject("select KPI_VALUE from dacp_kpi_value where OPTIME='" + lastmonth + "' and KPI_CODE='" + kpicode + "'", Integer.TYPE);
/*  76 */           Object mratex; if (((Integer)premvaluex).intValue() == 0) { Object mratex;
/*  77 */             if ((int)value == 0) {
/*  78 */               mratex = Integer.valueOf(0);
/*     */             } else {
/*  80 */               mratex = Integer.valueOf(1);
/*     */             }
/*     */           } else {
/*  83 */             mratex = Double.valueOf((value - ((Integer)premvaluex).intValue()) / ((Integer)premvaluex).intValue());
/*     */           }
/*     */         } else {
/*  86 */           premvaluex = null;
/*  87 */           mratex = null;
/*     */         }
/*  89 */         final Object premvalue = premvaluex;
/*  90 */         final Object mrate = mratex;
/*  91 */         String insertsql = "insert into dacp_kpi_value (OPTIME,KPI_CODE,KPI_NAME,KPI_VALUE,PRE_DVALUE,PRE_MVALUE,DRATE,MRATE) values (?,?,?,?,?,?,?,?)";
/*  92 */         template.update(insertsql, new PreparedStatementSetter()
/*     */         {
/*     */           public void setValues(PreparedStatement ps) throws SQLException {
/*  95 */             ps.setString(1, optime);
/*  96 */             ps.setString(2, kpicode);
/*  97 */             ps.setString(3, kpiname);
/*  98 */             ps.setDouble(4, value);
/*  99 */             ps.setObject(5, premvalue);
/* 100 */             ps.setObject(6, drate);
/* 101 */             ps.setObject(7, mrate);
/* 102 */             ps.setObject(8, this.val$mrate);
/*     */           }
/*     */         });
/*     */       }
/* 106 */       result.put("message", "生成数据成功！");
/*     */     } catch (Exception e) {
/* 108 */       e.printStackTrace();
/* 109 */       result.put("message", "生成数据出错！");
/*     */     }
/*     */     
/* 112 */     return result;
/*     */   }
/*     */ }


/* Location:              C:\Users\my\.m2\repository\com\asiainfo\dacp\dacp-dataos\1.0.0\dacp-dataos-1.0.0.jar!\com\asiainfo\dacp\catalog\controller\PortalKpiValueController.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */